package game.block.trap;

import game.block.Locator;
import game.block.command.Command;
import game.block.command.RemoveCommand;
import game.block.entity.MovableEntity;
import game.block.entity.TrapEntity;
import game.block.game.Board;
import game.block.tile.Tile;
import game.block.turn.Turn;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Vector2;

public class Quicksand extends TrapEntity {

    private float direction;
    private Sprite spiralSprite;

    public Quicksand(Vector2 pos, Tile tile) {
        super(pos, tile, QUICKSAND_TILE, TRAPTYPE.QUICKSAND);
        direction = 0;
        spiralSprite=new Sprite(new Texture(Gdx.files.internal(SPIRAL)));
    }

    @Override
    public void render(SpriteBatch sb) {
        sb.draw(sprite.getTexture(), position.x, position.y, 0, 0, sprite.getWidth(), sprite.getHeight(), SCALE, SCALE, 0, 0, 0, (int) sprite
                .getWidth(), (int) sprite.getHeight(), false, false);
        sb.draw(spiralSprite.getTexture(), position.x - TILE_SIZE * 2 + 8, position.y - TILE_SIZE * 2 + 8, TILE_SIZE * 2, TILE_SIZE * 2, spiralSprite
                .getWidth(), spiralSprite.getHeight(), SCALE / 1.2f, SCALE / 1.2f, direction, 0, 0, (int) spiralSprite.getWidth(), (int) spiralSprite
                .getHeight(), false, false);
    }

    @Override
    public void update(float delta) {
        super.update(delta);
        direction -= 180 * delta;
    }

    @Override
    public Command advance() {
        return null;
    }

    @Override
    public void applyEffect(MovableEntity block, Board gameBoard, Turn currentTurn, Tile tileMovedTo) {
        if (!block.counterEffect(this)) {
        	Locator.getAudio().playSound(SOUND.QUICKSAND.getValue());
            currentTurn.addCommand(new RemoveCommand(this, currentTile, gameBoard));
            currentTurn.addCommand(new RemoveCommand(block, currentTile, gameBoard));
        }
    }

    @Override
    public Command retract() {
        return null;
    }

    @Override
	public void setInfo() {
		info="Name:  Quicksand Trap\n\nFunction:  Destroys a block and creates a normal tile";
	}
}
